<template>
  <div class="cate">
    <div class="left">
      <van-sidebar v-model="active">
        <van-sidebar-item @click="category(item.id)" :title="item.name" v-for="item in goodsList" :key="item.id" />
      </van-sidebar>
    </div>
    <div class="right">
      <div class="flex">
        <div class="sec-main" v-for="item in shopsList" :key="item.id">
          <div class="main-img">
            <img :src="item.pic" />
          </div>
          <div class="main-text">{{ item.name }}</div>
          <div class="main-price">
            <div class="price-lfet">
              <div class="price-yi">￥</div>
              <div class="price-er">{{ item.minPrice }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, reactive, ref } from "vue";
import request from "../utils/request"
let active = ref(0);
let goodsList = ref<any>([])// 商品分类
let shopsList = ref<any>([])// 商品列表

let params = reactive({
  page: 1,
  categoryId: "",
  pageSize: 10
})// 商品分类数据

// 获取商品列表
function getGoodsList() {
  request({
    url: "shop/goods/category/all"
  }).then((res: any) => {
    // console.log(res);
    if (res.code === 0) {
      goodsList.value = res.data
      category(res.data[0].id)
    }
  })
}

// 获取分类详情
function category(id:any) {
  params.categoryId = id
  request({
    url: "shop/goods/list/v2",
    method: "post",
    params: params
  }).then((res: any) => {
    // console.log(res);
    shopsList.value = res.code === 0 ? res.data.result : []
  })
}

onMounted(() => {
  getGoodsList()
})

</script>

<style lang="scss" scoped>
.left {
  height: calc(100vh - 50px);
  overflow: auto;
  background: #f7f8fa;
}

.cate {
  width: 375px;
  display: flex;
}

.right {
  // width: 275px;
  flex: 1;
  height: calc(100vh - 50px);
  overflow: auto;

}

.flex {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}

.sec-main {
  width: 137px;
}

.main-img {
  width: 127px;
  height: 127px;
  margin: 0 auto;
}

.main-img img {
  width: 127px;
  height: 127px;
}

.main-text {
  width: 107px;
  height: 36px;
  margin: 0 auto;
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.3;
  overflow: hidden;
}

.main-price {
  width: 107px;
  margin: 0 auto;
}

.price-lfet {
  width: 21px;
  display: flex;
  align-items: center;
}

.price-yi {
  font-size: 12px;
  color: #1ba784;
}

.price-er {
  font-size: 18px;
  color: #1ba784;
}
</style>